package controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.AppInfo;
import pojo.AppVersion;
import pojo.BackendUser;
import service.AppInfoService;
import service.AppVersionService;
import service.BackendUserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


@Controller
public class BackendUserController {
    @Resource
    private AppInfoService appInfoService;
    @Resource
    private BackendUserService backendUserService;

    @Resource
    private AppVersionService appVersionService;

    @RequestMapping("/loginBackendUser")
    public String loginBackendUser(String userCode, String userPassword, Model model, HttpSession sessioon){
        BackendUser backendUser=null;
     //   DevUser devUser=new DevUser();
      //  devUser.setId(0);
        backendUser =backendUserService.loginBackendUser(userCode,userPassword);
        if(backendUser!=null){
            sessioon.setAttribute("status",appInfoService.DataDictionaryList("APP_STATUS"));
            sessioon.setAttribute("appCategorylist",appInfoService.appCategoryList(null));
            sessioon.setAttribute("flatforms",appInfoService.DataDictionaryList("APP_FLATFORM"));
            sessioon.setAttribute("backendUser",backendUser);
        //    sessioon.setAttribute("devUser",devUser);
            return "index";
        }
        model.addAttribute("userCode",userCode);
        model.addAttribute("userPassword",userPassword);
        return "login";
    }
    //审核AppShowAppVersionAppInfo
    @RequestMapping("/ShowAppVersionAppInfo")
    public String ShowAppVersionAppInfo(Integer appId,Model model){
        AppInfo appInfo=appInfoService.appInfoListId(appId);
        model.addAttribute("appInfo",appInfo);
        AppVersion appVersion=appVersionService.AppVersionID(appId);
        model.addAttribute("appVersion",appVersion);
        model.addAttribute("ShowAppVersionAppInfo","ShowAppVersionAppInfo");

        return "index";
    }
    @RequestMapping("/UpdateAppInfostatus")
    @ResponseBody
    public int UpdateAppInfostatus(Integer appId,Integer status){
        int update=appInfoService.UpdateAppInfostatus(appId,status);
return update;
    }
}
